<template>
	<view class="content ">
		<view class="modify">
			<view class="userImg">
				<button type="default" class="btn" open-type="chooseAvatar" bindchooseavatar="onChooseAvatar"></button>
				<image src="../../../static/logo.png" mode="widthFix"></image>
			</view>
			<view class="userItem">
				<view class="user-modify">
					<view class="color-333">昵称</view>
					<uv-input placeholder="请输入昵称" border="" color="#999" fontSize="28rpx"></uv-input>
				</view>
				<view class="user-modify">
					<view class="color-333">账号</view>
					<uv-input placeholder="请输入账号" border=""  color="#333"></uv-input>
				</view>
				<view class="user-picker">
					<view class="color-333">生日</view>
					<picker mode="date" :start="startDate" :end="endDate" @change="onDateChange">
						<view class="picker-text">{{birthday || '请选择生日'}}</view>
					</picker>
				</view>
				<view class="user-picker">
					<view class="color-333">性别</view>
					<picker mode="selector" :range="genderList" range-key="label" @change="onGenderChange"
						style="width: 80%; ">
						<view class="picker-text">
							{{ selectedGender.label || '请选择性别' }}
						</view>
					</picker>
				</view>
				<view class="user-modify">
					<view class="color-333">简介</view>
					<uv-input placeholder="一句话描述自己..." border=""></uv-input>
				</view>
			</view>
			<view class="">
				<view class="modify-btn">确定修改</view>
				<view class="exit-btn">退出登录</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				birthday: '',
				startDate: '1900-01-01',
				endDate: this.getCurrentDate(),
				genderList: [{
						label: '男',
						value: 1
					},
					{
						label: '女',
						value: 2
					}
				],
				selectedGender: {}

			};
		},
		methods: {
			// 头像上传
			onChooseAvatar(e) {
				// 获取头像临时路径
				const {
					avatarUrl
				} = e.detail
				console.log('头像路径:', avatarUrl)

				// 上传头像或保存到本地
				this.setData({
					avatar: avatarUrl
				})
			},
			// 生日选择
			onDateChange(e) {
				this.birthday = e.detail.value
			},
			getCurrentDate() {
				const date = new Date()
				return `${date.getFullYear()}-12-31`
			},
			// 性别选择
			onGenderChange(e) {
				const index = e.detail.value
				this.selectedGender = this.genderList[index]
			}
		}

	}
</script>

<style lang="less">


	.modify {
		padding: 30rpx;
		display: flex;
		gap: 40rpx;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		.userImg {
			width: 180rpx;
			height: 180rpx;
			position: relative;

			image {
				border-radius: 50%;
				width: 100%;
			}

			.btn {
				width: 180rpx;
				height: 180rpx;
				position: absolute;
				top: 0;
				left: 0;
				background-color: transparent !important;
				padding: 0;
				margin: 0;
				line-height: normal;
				border: none !important;
				opacity: 0;
			}

		}

		.userItem {
			width: 90%;
			padding: 30rpx;
			background-color: #fff;
			display: flex;
			flex-direction: column;
			gap: 10rpx;

			.user-modify {
				padding: 30rpx 0rpx;
				border-bottom: 1px solid #e9e9e9;
				display: flex;
				justify-content: space-between;
				align-items: center;

			}

			.user-picker {
				display: flex;
				align-items: center;
				gap: 30rpx;
				padding: 30rpx 0rpx;
				border-bottom: 1px solid #e9e9e9;

				.picker-text {
					font-size: 28rpx;
					color: #999;
				}
			}
		}
		.modify-btn{
			padding: 30rpx 120rpx;
			background-color: #e2c87d;
			border-radius: 50rpx;
			margin: 30rpx 0rpx ;
		}
		.exit-btn{
			padding: 30rpx 120rpx;
			border-radius: 50rpx;
			border: 1px solid #e2c87d;
		}
	}
</style>